const path = require('path')
const HtmlPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')

module.exports = {
  entry: {
    index: path.resolve(__dirname, 'src/pages/index/index.js'),
    news: path.resolve(__dirname, 'src/pages/news/news.js'),
    news_today: path.resolve(__dirname, './src/pages/news/today/today.js')
  },
  output: {
    path: path.resolve(__dirname, './dist'),       // 绝对路径
    filename: 'js/[name].js',
    publicPath: process.env.NODE_ENV === 'development' ? '/' : '../'
  },
  devServer: {
    host: '127.0.0.1',
    port: '8899',
    publicPath: '/'
  },
  module: {
    rules: [
      {
        test: /\.html$/,
        loader: 'html-loader'
      },
      {
        test: /\.(png|jpg)$/,
        loader: 'url-loader',
        options: {
          limit: 3000,
          name: 'imgs/[name].[ext]',
          publicPath: process.env.NODE_ENV === 'development' ? '/' : '../'
        }
      },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: 'css-loader',
          publicPath: '../'
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('css/style.css'),
    new HtmlPlugin({
      filename: 'pages/index.html',
      template: './src/pages/index/index.html',
      chunks: ['index']
    }),
    new HtmlPlugin({
      filename: 'pages/news.html',
      template: './src/pages/news/news.html',
      chunks: ['news']
    }),
    new HtmlPlugin({
      filename: 'pages/today.html',
      template: './src/pages/news/today/today.html',
      chunks: ['news_today']
    })
  ]
}